#include <iostream>
#include <iomanip>
#include <sstream>

class hex_data
{
	unsigned char* data_;
	int &len_;
public:
	explicit hex_data(unsigned char* data, int &len) : data_(data), len_(len) {}

	template< typename CharT, typename TraitsT >
	friend std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, hex_data const& obj)
	{
		strm << std::hex;
		for (int i = 0; i < obj.len_; i++)
		{
			strm << std::setw(2) << std::setfill('0') << (unsigned int)obj.data_[i];
		}
		return strm;
	}

        template< typename CharT, typename TraitsT >
        friend std::basic_istream< CharT, TraitsT >& operator>> (std::basic_istream< CharT, TraitsT>& strm, hex_data &obj)
        {
                strm >> std::hex;
		int i = 0;
		int a = 0;
		while(!strm.eof())
		{
			strm >> a;
			obj.data_[i++] = (unsigned char)a;
		}
		obj.len_ = i;
                return strm;
        }

};

int main()
{
/*
	int a,b,c;
	std::cin >> std::hex >> a >> b >> c;
	std::cout << "a=" << a << " b=" << b << " c=" << c << std::endl;
*/

	unsigned char data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15};
	int len = sizeof(data);
	std::cout << hex_data(data, len) << std::endl;

	hex_data a(data, len);
	std::string s("01 02 03 04 0a 0d 0e 0f");
	std::stringstream ss(s);
	ss >> a;

	std::cout << hex_data(data, len) << std::endl;

	return 0;
}

